Part Five: Crystal Reports 26.0 Introduction to Crystal Reports This chapter introduces Crystal Reports, shows you how to start the program, introduces you to some of the things the program can do, and familiarizes you with some of the "nuts and bolts" of using the program. 26.1 About This Part of the Manual This part of the manual contains all of the information you should need for building reports quickly and easily using Crystal Reports. It is divided into three chapters: Chapter Description 26.0 Introduction to Crystal Reports Introduction gives you a brief overview of Crystal Reports. It familiarizes you with the Crystal Reports screens, using the mouse, error messages, and the help facility. 27.0 Using Crystal Reports This chapter conceptually leads you through the process of creating a report with Crystal Reports. It suggests a methodology for creating reports starting with nothing more than a one sentence statement of purpose for the report. 28.0 Practical Crystal Reports Practical Crystal Reports is a "How to" chapter. It contains a variety of report creation topics and additional information on the practical aspects of using Crystal Reports to solve typical reporting problems. For information on topics not found in these chapters, refer to the Crystal Reports Help system. This part of the manual assumes that you understand the basic concepts and usage of Microsoft DOS or PC-DOS, and Windows 3.0 or higher. The procedures also assume that you will be using a mouse in the creation of your reports. While the instructions occasionally indicate keyboard methods for using the program, the instructions are generally mouse-oriented since most Windows users have a mouse. 26.1.1 Special Notations Used in this Part The following notations are used throughout this part of the manual: o Delete means the Del key on your numeric keypad. o Escape means the Escape or Esc key on your keyboard. o Enter means the Enter, Return, or CR key, depending on which of these keys appears on your keyboard. o Click means to click the left mouse button one time. o Double click means to click the left mouse button twice, in quick succession. o The term Cursor Keys means the Pg Up, Pg Dn, and Arrow Up, Arrow Down, Arrow Right, Arrow Left, Home, and End keys on your numeric keypad. o Ctrl+Key, Shift+Key, and Alt+Key are examples of the notation for two key combinations. They mean to press the first key in the combination (Control, Shift, or Alt), and, while keeping it depressed, to press the second key in the combination (designated as Key). o Text enclosed in double brackets (for example, << information >>) is intended to expand or explain the information that it follows. o Field names in formulas are italicized. o Insert|Formula means to select the Formula option from the Insert menu. o Drag, when used in talking about field boxes, means to position the cursor on a field box, depress the left mouse button, and keep the button depressed while moving the field to a new position. o Drag, when used in talking about text, means to depress the left mouse button and, while it is depressed, move the I-beam cursor across the text of interest to highlight and thus select it. o Computer type indicates data that you are to enter using the computer keyboard. It is also used to show example formulas. 26.2 Starting Crystal Reports You can start Crystal Reports in two ways: o from the DOS command line o from the Windows environment. 26.2.1 From DOS To start Crystal Reports (and Windows at the same time) from the DOS command line, type: cd and the name of the directory into which you installed Crystal Reports. For example, if you installed Crystal Reports in the default Crystal Reports directory, type: cd \CRW and then press Enter. At the prompt, type: win CRW and press Enter. Windows and Crystal Reports are both started. 26.2.2 From Windows Once in Windows, select the group window that holds the Crystal Reports icon. o If you're using a mouse, double click on the Crystal Reports icon to start the program. o If you're using the keyboard, use the arrow keys to select the icon and then press Enter. You can also start Crystal Reports from within Windows by double clicking on the file name CRW.EXE in the File Manager. 26.2.3 The Crystal Reports Registration Dialog Box The Crystal Reports Registration dialog box appears whenever you start Crystal Reports unless you have registered your copy of the program with the company, received a serial number, and entered it in the Enter serial number... edit box to disable this opening dialog box. There are two good reasons to register your copy of Crystal Reports: o Registration entitles you to technical support should you ever require assistance in using the product. o Registration assures you that you will be notified whenever the product is upgraded to offer new features, benefits, and efficiencies. The Crystal Reports Registration dialog box options are as follows: o Enter serial number... edit box: Use this edit box to enter the serial number that Crystal Services sends you when you register the program. Be careful to enter the serial number correctly. o Proceed to Crystal Reports button: Use this button to close out the dialog box and go directly into the Crystal Reports program. The button will be useful until you receive and enter your registration serial number. At that time the Crystal Reports Registration dialog box will no longer appear when you start the program. o Edit Registration Info button: Use this button to enter/edit product registration information. The Edit Registration Info button takes you to the Crystal Reports Registration dialog box. Use this dialog box to enter your name, company name, and phone and fax numbers. Crystal Reports stores this information and displays it and/or prints it out automatically when you print out the registration form, call up system information (via the Help|System Information command), or send in a technical support request (via the Help|Technical Support Request command). o Print Registration Form button: Use this button to print a copy of the completed registration form. 26.2.4 How to Register Your Copy of Crystal Reports Use the following procedure to register your copy of Crystal Reports. 1. Click the Edit Registration Info button. The Crystal Reports Registration dialog box appears. 2. Enter your name, address, phone, and fax in the edit boxes provided, and click OK when finished You are returned to the Crystal Reports Registration dialog box. 3. Click the Print Registration Form button. Crystal Reports prints out a copy of your completed registration form. 4. Fax the form to Crystal Services at the number that appears on the form, or mail it to Crystal Services at the address that appears on the form. 5. In a few days, the company will mail or fax you back your serial number. 6. Enter the serial number in the Enter serial number... edit box, and click the Proceed to Crystal Reports button when finished. This takes you to Crystal Reports and disables the dialog box so it no longer appears when you start the program. 26.3 Quick Start If you are an experienced Windows user who wants to get right into the program, follow these steps to set up a Crystal Reports report for the first time after you install the program. 1. Start Crystal Reports by double clicking on the Crystal Reports icon in the Program Manager. 2. Select New Report from the File menu. 3. When the Choose Database File dialog box appears, select the first database you want to activate for your report and press OK when finished. The Crystal Reports Report Editor appears with Page Header, Details, and Page Footer sections set up on your report template. The sections are all blank initially. Create your report by inserting and formatting items in each of these sections. 4. The Insert Database Field dialog box appears on screen with the Report Editor. The Insert Database Field dialog box displays a list of all of the fields in the active database. To speed the entry of multiple fields, the box remains on screen until you click on the Done button. You can move the dialog box to a new location if you wish. 5. Select the first field you want to appear on the report. A rectangular insertion cursor appears. 6. Position the cursor at the point in the Details section where you want your field to appear, and click the left mouse button to enter it. Crystal Reports marks the field position with a rectangular box. The characters in the box indicate whether the field is text (XXX...), number (555,...), dollar value ($555,...) date (YYYY-M...), or Boolean (T/F). The number of characters in the box indicate the number of characters allowed for the field in the database from which it came. 7. Repeat Steps 5 and 6 until you have placed all the fields you want to place. 8. To create a title, select Insert|Text Field, type in the information you want to appear, click Accept when finished, and position the field where you want it in the Page Header section. You can also insert database fields or special fields in that section from the Insert menu. 9. To see how your results will print, select Print To Window from the Print menu. Close the window when you are finished with your review. 10. If you want to: o change the placement or width of a field o format the field o insert a subtotal or grand total for a field o delete a field click the field box for that field. Black handles appear on the right and left sides of the field box to indicate that it has been selected. o To change the placement of the field, drag the field box to its new position using the mouse or the arrow keys. The arrow keys move the field box one grid position each time you press them. o To change the width of the field, drag the right or left handle using your mouse or use a Shift-Arrow combination on your keyboard. o To format or subtotal the field, click the right mouse button while the cursor is inside the field. A pop-up menu appears listing your various options. - To change the font, select Change Font and refine your selection using the Font dialog box when it appears. - To change the format (alignment within field; number, currency, or date display; etc.) select Change Format and refine your selection using the Field Format dialog box when it appears. - To insert a subtotal, select Insert Subtotal and refine your selection using the Insert Subtotal dialog box when it appears. In this dialog box you select the field and the condition that triggers a new subtotal whenever the field's value changes, and you select the sort direction: Ascending (A to Z, 1 to 9) or Descending (Z to A, 9 to 1). The program creates a new section to hold the subtotal. NOTE: The program automatically sorts the data (based on the field that triggers the subtotals) before it subtotals. Manually entering a subtotal sort is not necessary. - To insert a grand total, select Insert Grand Total. The program creates a new section to hold the grand total. - To delete the field, select Delete Field. 11. To create a formula to make data calculations or comparisons, select Formula Field from the Insert menu. Enter a name for your formula in the Insert Formula dialog box, and enter the formula itself in the Formula Editor when it appears. Enter fields, operators, and functions by selecting them from their respective scroll lists. You can get complete information on each available Function and Operator via the Help button, and you can check your formula syntax via the Check button. Entering a Crystal Reports formula is similar to entering a formula in a spreadsheet cell. When finished editing, select Accept and place the formula just like you do a database field. 12. To change the sort order, select Record Sort Order from the print menu. Select the field(s) you want Crystal Reports to use for sorting the report data. 13. To change the sort and group by field, select Group Section from the Edit menu. Select the group section of interest from the list that appears in the Edit Group Section (sections) dialog box, and select the new "trigger" field from the Edit Group Section (edit) dialog box when it appears. 14. If you want to limit your report to specific records (for example, the records of California customers that have YTD sales greater than $10,000), click the first field on which you want your selection to be based (in this case the State field) and choose Select Records from the Print menu or the right mouse button pop-up menu. Answer the questions that appear in the Select Records dialog box and click OK when finished. If your selection is based on more than one field, repeat the process with the remaining field(s) until you have completed entering your selection specifications. 15. When finished, you can print your report by selecting Print To Printer from the Print menu. 26.4 About Crystal Reports Crystal Reports is a powerful yet easy to use program for creating custom reports, lists, and form letters using data from your existing databases. The program works by establishing connections with one or more of your databases. Using these connections as conduits, Crystal Reports draws in the values from database fields you select and uses them in the report, either in their original form or as part of a formula that generates more sophisticated values. Crystal Reports was designed to work with all kinds of data: numbers, currency, text, dates, and Boolean (Yes/No) fields. It has a wide range of built-in tools that you can use to manipulate that data to fit your needs. Using these tools, you can: o make calculations and comparisons of data values, o calculate subtotals, and grand totals of field values, o calculate group averages, count the records in a group, and test for minimum and maximum values, o test for the presence of specific values, o present data only if certain conditions are met, o evaluate logical relationships between values, o convert data from one type to another, o merge text with other text, o merge text with data field data, and o perform numerous other useful, data-related activities. The data can be placed wherever you want it on the report, highlighted with special fonts and font sizes. With Crystal Reports, your reports can be as simple or as complex as your needs demand. 26.4.1 How Crystal Reports Prepares Reports Crystal Reports prepares reports by reading data in the database files you have selected and making that data available for use in your report. o If you wish to use data in a single data file, you simply choose that file when you create the report. o If you wish to use data in multiple data files, you need to select the files and also to indicate the field or fields in each file that Crystal Reports is to use to match data. NOTE: Crystal Reports does not write data to your original data files. Your original files remain unchanged using Crystal Reports, no matter how much you might manipulate the data you select. 26.4.2 Databases that Work with Crystal Reports Crystal Reports can build reports using the standard data files generated by dBASE for Windows and Paradox for Windows as well as with DOS versions of dBASE and Paradox. 26.5 The Crystal Reports Window The Crystal Reports window is simple and easy to understand: o the Title Bar appears at the top of the window, o the Menu Bar appears just below the Title Bar, and o the Button Bar appears just below the Menu Bar. 26.5.1 Title Bar The Title Bar displays the name of the program running in the window, Crystal Reports. You can use the title bar to activate the window (if the window is buried in a cascade of windows) or to move the window (by depressing the left mouse button with the pointer on the title bar and then, while the button is still depressed, dragging the window to a new location), or to maximize the window (by double clicking on the title bar). 26.5.2 The Menu Bar The Menu Bar is Crystal Reports' command center. Each option on the menu bar calls up a drop down menu of commands that you can use to create, modify, print, and save your reports. Each menu is listed in the table below: File The File menu includes commands you can use to open, close, and save files, to save files under a different file name, print the file to a printer, and create new report files. It also includes a command you can use to exit Crystal Reports. Additionally it contains a command that allows you to configure Crystal Reports to your specifications. Edit The Edit menu allows you to modify aspects of your report. The menu includes commands you can use to edit formulas, to edit and delete group sections, and to change summary operations. It also contains commands for cutting, copying, and pasting text, clearing (deleting) report elements, toggling the display of field names on and off, and changing your report title. Insert The Insert menu is the central menu you use for creating reports. The menu includes commands you can use to insert database fields, text fields, and formula fields; subtotals, grand totals, summaries (counts, averages, etc.), and group sections; print date, page number, record number and group number fields; and graphics, lines, and boxes. Format The Format menu includes commands for changing the look of the elements in your report. It includes commands for changing fonts, and formatting fields, report sections, graphics, lines, and boxes. The menu also provides commands for adding field borders as well as background color and drop shadows for your fields. Data- The Database menu is used to select and delete databases for use base with your reports, to change the alias you use to identify the database, and to link and unlink databases. It also has a command, File Location, for directing Crystal Reports to look for database files in new locations. Two verify commands can be used to adapt your reports to minor changes in database structure. Print The Print menu includes commands that let you print your report to a print window, to a disk file, or to a printer, print the report definition (a report describing your report), select the records or groups to be included in your report, select the order in which report data is to be sorted (by record or by group), and select a printer if you want the report to print on something other than the default printer. Window The Window menu includes commands that let you rearrange icons and windows. It also lists the report windows that are open and includes a command that lets you close all report windows at once, if desired. Help The Help menu includes a command that takes you to Crystal Reports' main help index, a command that will give you information about the Crystal Reports version you are using, and other help-related topics. 26.5.3 The Button Bar Crystal Reports groups several commonly-used commands on a Button Bar that remains on screen at all times (unless you choose to turn it off). Each command is represented by an individual button, and each button displays a graphic that visually describes the command. You activate Button Bar commands by clicking the appropriate button one time with the left mouse button. The Button Bar eliminates some of the steps needed to activate the included commands, and it can thus greatly speed your work in creating reports. 26.5.4 The Status Bar The status bar at the bottom of the report window displays valuable information to help you use Crystal Reports more efficiently: o Button bar functions: When the cursor is over a Button Bar button, the Status Bar displays a short description of the button's function. o Menu command descriptions: When you highlight a menu command, the Status Bar displays a short description of the command. To highlight a menu command, click the menu name and move to the command using the Down Arrow key. o Current selections: When you select or place a graphic, field, text field, graphic line or box, special field, or formula, the status bar displays the name of the item selected. It displays: - the file name for a graphic, - the alias and field name for a field, - the text in a text field, - the words Line for a line and Box for a box, - the field type for special fields (PrintDate, RecordNumber, etc.) - the formula name for a formula. o Graphic Coordinates: When you select or create a bit-mapped graphic, a graphic box, or a graphic line, the program displays the coordinates for the left, right, top, and bottom sides of the graphic element. 26.6 Right Mouse-Button Capabilities When you are working in the Report Editor, you can speed up your work considerably using Crystal Reports' right mouse button capabilities. When the cursor is positioned on a report element (a field, a group field, a formula, etc.) and you click the right mouse button, Crystal Reports displays a pop-up menu right next to the element. Unlike Crystal Reports' standard menus that group commands by function (editing, inserting, etc.), these pop-up menus are element-specific: that is, they contain only those commands from Crystal Reports' primary menus that are available for use with the selected element. The pop-up menus are valuable because: o they display the name and source (alias) of the element at the top of the menu so you can identify the elements on your report with a single mouse click, o they appear right next to the selected element making them quicker and easier to access than Crystal Reports' main menus, o they contain only the commands you need; you don't need to search for commands on a more comprehensive menu, o they make it easier to learn Crystal Reports because: - they eliminate the need to remember where to find a command, and - they make it easier to pick the right command since you're dealing with only a compact list of, and o they spotlight the things you can do with an element making it an easier system to use when you are under pressure or distracted. Use the following procedure to use the right mouse button menus: 1. Position the cursor on the element of interest. 2. Click the right mouse button. The pop-up menu appears. 3. Select the command of interest from the pop-up menu. These options work exactly like the corresponding options that appear on Crystal Reports' primary menus. For information on using any of these menu options, see the corresponding option in Crystal Reports Help. NOTE: If you have swapped left/right mouse buttons via the Control Panel, the left mouse button will activate the pop-up menus. 26.7 Crystal Reports Report Windows When a Crystal Reports report appears, it appears in a report window. A report window has a title bar, minimize and maximize buttons, and a control menu box like the Crystal Reports window. Unlike the Crystal Reports window, the report window does not have its own menu. Instead, the commands from the Crystal Reports menu remain visible and are active for the document window. Also unlike the Crystal Reports window, the document window has scroll bars at the bottom and along the right hand edge. Usinh these scroll bars you can reveal parts of the document that aren't immediately showing in the window. 26.8 Getting Help with Crystal Reports Crystal Reports offers a comprehensive help system to support you during every step of the report development process. 26.8.1 Context Sensitive Help Context sensitive help gives you immediate help with a screen element of interest (menu command, dialog box, etc.). The program takes you directly to the help information you seek without the need to traverse the indexing system. NOTE: To get help on a specific menu command, click the menu name and then use the Down Arrow key to highlight the command of interest. Once the command is highlighted, press F1. 26.8.2 Indexed Help Indexed help takes you to the help indexing system, a hierarchy of indexes which is designed to help you target your topic of interest. Using the indexing system, you can select a broad topic of interest from the first index and then narrow your selection using the next index that appears, then the next. etc. 27.0 Using Crystal Reports This chapter provides a structured approach to preparing reports with Crystal Reports. 27.1 Using Crystal Reports The approach of this chapter in preparing reports with Crystal Reports includes the following elements: o deciding on the content of your report, o developing a prototype on paper, o setting up the prototype using Crystal Reports, o manipulating the data with formulas and functions, o grouping, summarizing, and sorting your data, o editing and formatting the data, o specifying the records/groups to be included in the report, and o printing the finished report. This is not a hands-on chapter, but an important introduction that can make your report creation work more efficient and more satisfying. The chapter has been designed to provide you with a conceptual understanding of Crystal Reports as well as a brief introduction to Crystal Reports' powerful features. 27.2 Deciding on the Content of Your Report Before you do anything else, you should outline the information you want your report to provide. Use the following list of questions as a guide in making that outline: o What is the overall purpose of the report? o Who is going to read the report? o What is the report title going to be? o What information do you need besides the title to identify the report? - Where is that information to come from? - If the information exists in a database, what types of fields is the data stored in: number, text, etc.? o What identifying information do you want to appear at the bottom of each page? - Where is that information to come from? - If the information exists in a database, what types of fields is the data stored in: number, text, etc.? o What specific data do you want to appear in the body of the report? - Where is that data to come from? - Does that data exist in data fields or does it need to be calculated from data field values? - What kind of fields is the data stored in: number, text, etc.? - Do you want to show totals? - What kind? - What do you want to total? o What information, if any, do you want flagged on the report? - How do you want it flagged? o What information do you want highlighted in some way so that it really stands out? o Do you want the report to be based on all records in the database or only on specified records? 27.2.1 Purpose What is the overall purpose of the report? Reports are management tools. Their purpose is to help individuals quickly grasp the essential elements and relationships found in raw data so they can make effective decisions. For a report to be effective, it has to present the right data in a logical way. If it presents the wrong data or if it presents the right data in a haphazard manner, the report may slow the decision making process or even encourage incorrect decisions. A good starting place in the development of a report is to write out the purpose of the report in a sentence or two. The purpose statement helps you focus on your primary needs, and it gives your report both a starting point and a goal. Here are some examples of purpose statements: o The purpose of this report is to show monthly and year-to-date sales by sales rep, compare this year's numbers to last year, and flag reps who are seriously deficient. o The purpose of this report is to show sales activity for each item in inventory, and to suggest reorder quantities based on that activity. o The purpose of this report is to calculate bowling averages and handicaps for each member of the bowling league. Clarifying the purpose of the report before you start is a critical step in the overall process. A report without a clear purpose is like a meeting without a clear agenda; it rambles and accomplishes little. 27.2.2 Readers Who is going to read the report? A single report is often used by many individuals. A detailed, company-wide sales report, for example, may be used by sales reps, the regional sales manager, the national sales manager, and the Chief Operating Officer (COO). Each of these individuals will be interested in different aspects of the report. o A sales rep will use the report to evaluate his/her individual sales performance and to compare that performance to that of other reps in the region. o The regional sales manager will use the report to evaluate the reps in his/her region and to compare the region's performance to that of other regions. o The national sales manager will use the report to evaluate the performance of his/her regional managers and to compare overall sales to the current sales forecasts. o The COO will use the report to evaluate the performance of the Vice President of Marketing and the sales department as a whole, and to project such things as manufacturing needs, warehouse locations, etc. Since each of the users of the report has different interests, it is important to plan the report so it includes the information each of the users is looking for. 27.2.3 Title What is the report title going to be? Write out a working title for your report. You may decide to change it later, but at least you will have a title to use when creating your prototype report. 27.2.4 Other Header Information What information do you need besides the title to identify the report? Are you going to include identifying information in addition to your report title? You may wish to include the current date, information on who prepared the report, a block of text to describe the purpose of the report, the range of data covered, etc. If you are going to include such information, write it down so you can use it in preparing your prototype. 27.2.5 Header Information Sources Where is that information to come from? The information can come from a variety of sources, depending on the kind of information you plan to use. For example, the current date can be inserted using the Crystal Reports Insert|Print Date Field command. Information on who prepared the report might be drawn from individual data fields in the database(s) used. (If it is to be drawn from a database, what database? Or, what combination of databases?) A block of text can be created and entered on the face of the report itself. As you begin to think of where the information is to come from, you begin formally structuring the report. 27.2.6 Data Types in the Header If the information exists in a database, what types of fields contain the data: number, text, etc.? Crystal Reports uses different rules for working with different types of data. You will find it helpful later if you note the data type of each piece of data you plan to draw from a database. 27.2.7 Footer Information What identifying information do you want to appear at the bottom of each page (page number, report name, author's name, "Confidential," etc.)? 27.2.8 Footer Data Sources Where is that information to come from? 27.2.9 Data Types in the Footer If the information exists in a database, what types of fields is the data stored in: number, text, etc.? 27.2.10 Report Body Data What specific data do you want to appear in the body of the report? When you think of a report, it is probably the body of the report that you think of. The body should contain all the data that you need to fulfill the statement of purpose you wrote for the report. It should also contain all of the data needed by the various users that you have identified. You might find it helpful to list first the basic data that is required to fulfill the purpose statement, and then list the more specific kinds of data needed by the various users. 27.2.11 Body Data Sources Where is that data to come from? This step requires you to look at the available databases. Crystal Reports allows you to combine data from different databases to create your reports, so you have a great deal of flexibility in your work. o Much of the data in a typical report will be taken directly from data fields. Which data fields will you be using and where are they located? o Other data will be calculated based on data fields. Which data fields will be used in the calculations? o Still other data will be input directly into the report (headings, text blocks, etc.). Which data will you enter directly on the report, without drawing it from data fields? 27.2.12 Existing or Calculated? Does that data exist in data fields or does it need to be calculated from data field values? Some report information can be drawn directly from data fields (sales information, for example); other information will have to be calculated based on data field values (sales commission, for example, based on the relationship of sales to quota). In your planning, it can be helpful to segregate or flag data that needs to be calculated from that which can be used directly. 27.2.13 Data Types in the Body What kinds of fields contain the data: number, text, etc.? While it is important to understand data types for all data you will be using, it is of critical importance that you know the data type for data fields that will be used in calculations. Functions and operators work with specific kinds of data, so it's important to know the data type to know which functions and operators you can use in your calculations. 27.2.14 Groups Do you want your data organized into groups? How do you want it grouped? By customer? By date? 27.2.15 Group Values Do you want to show a subtotal at the end of each group? A count? An average? Crystal Reports allows you to specify several kinds of group values. 27.2.16 Group Value Positions Where do you want the group values to appear. With the group data? With the group data but on a page separate from other groups? Only at the bottom of the page? Crystal Reports gives you all of these options. 27.2.17 Grand Totals, Grand Total Averages, etc. Do you want to total (or average, count, or determine the maximum or minimum value included in) all the values in any column on your report? Crystal Reports allows you to do this and place the grand total (or the grand total average, grand total count, etc.) at the bottom of the selected column. 27.2.18 Flags What information, if any, do you want flagged on the report? You may want to call attention to some data by flagging it on your report. For example, non-moving inventory items are often flagged on inventory reports so they can be given special attention. If you want any information flagged, identify the information and the parameters for flagging. Using the inventory report example, you might want to flag each item that has shown no activity during the last month, during the last three months, or during some defined period. 27.2.19 Flag Options How do you want it flagged? You may want to flag items with an asterisk or some other symbol, or you may want a word to appear as a flag. In any case, you should write out flagging instructions so they are handy. 27.2.20 Highlights What information do you want highlighted in some way so that it really stands out? Crystal Reports gives you the opportunity to underline report elements, or to change the fonts or font size used for specific report items. All of these formatting tools can be used to highlight key data on a report. If you have data that you want highlighted, you should write down highlighting instructions so they are handy too. 27.2.21 Record or Group Selection Do you want the report to be based on all records or groups in the database or only on specified records or groups? Crystal Reports gives you the opportunity to base a report on all records in a given database, or on a limited set of records from the database. Using Crystal Reports you can select records based on simple date ranges or comparisons, or you can create complex formulas to identify the records to be included. Take a few minutes to determine the records needed for your report and list the criteria to be used for selecting those records. 27.2.22 Sorting Do you want your data sorted based on record or group values? Crystal Reports gives you both alternatives. 27.3 Developing a Prototype on Paper Graphic designers generally begin their work on a magazine cover, brochure, or display advertisement with a rough pencil sketch. They often use boxes, circles, or other symbols to represent the graphic elements they intend to include in the final product, and they often use lines or scribbles to represent text. Doing the rough design on paper, in pencil, helps them create a "look" for each page. It helps them find a balanced way of positioning the various elements before they begin working with sophisticated graphics tools. We think you will find a similar exercise helpful in designing your Crystal Reports reports. While a paper prototype is useful regardless of your expertise with Crystal Reports, it is particularly valuable when you are first learning to use the Crystal Reports program. With the paper prototype at hand, you can put your full effort into learning and using the Crystal Reports commands instead of trying to design and learn at the same time. Use the following procedure to design a paper prototype with Crystal Reports: o Get paper of the size you'll be using for your finished report. o Position your title and other descriptive header information, using boxes or lines to represent report elements. o Position your footer information. o Review the page for balance. o Look at the information you intend to include in the body of your report. - Count the number of fields you will be using and estimate the appropriate spacing between fields. - Use rectangles to pencil in the fields using your estimated spacing. - Change the spacing if necessary. - Decide on a logical sequence for presenting the report data. - Label the fields to indicate that sequence. o Use small boxes to indicate group values and totals. o Place some random flags where you want the flags to appear. o Darken any elements you want highlighted so they stand out from the rest of your prototype. o Review your finished product for look and balance, and make changes as needed. 27.4 Setting Up the Prototype Using Crystal Reports Once you have completed your paper prototype, it is a straightforward process to recreate that prototype in the computer, using Crystal Reports. Before you do, it is important to understand how Crystal Reports' report editing process works. NOTE: This section assumes that you are new to Crystal Reports and that you plan to build a simple report using data from a single database. No advanced topics are covered in this section. When you want to begin a new report, Crystal Reports displays the Choose Database File dialog box. You use this dialog box to select the database file(s) that contain the data you want to use in your report. You will first select the directory and, once in the directory, you can select the database file you identified earlier in Deciding on the Content of Your Report. 27.5 The Report Editor Once you select your database, Crystal Reports displays the Report Editor screen. You use this screen to insert and format data and to watch your report take shape. When you open a new report, Crystal Reports automatically creates three sections in the Report Editor: o A Page header section - this section is generally used for the report title, field headings, and other information that you want to appear at the top of each page. o A Details section - this section is the body of the report. The bulk of your report data will generally appear in this section. o A Page footer section - this section usually contains the page number and any other information that you want to appear on the bottom of each page. The name of each section appears in the gray area to the left of the Report Editor edit box. o You build your report by inserting data fields, formulas, and other report elements (record counts, record numbers, etc.) in the Details section of the editor. You use the Insert menu, in most cases, to select or create the elements you want to insert on the report. The Report Editor uses rectangular element markers to indicate the size, position, and data type of the report elements you have inserted. o You add subtotals (and other group values) by selecting a field to subtotal and then telling Crystal Reports the conditions that are to generate a new subtotal or group value (change of customer number, change of sales rep, etc.). Crystal Reports creates group value sections as needed and places the group value in the section. Again, Crystal Reports uses rectangular field boxes to represent the group values. o You insert grand totals in the Grand Total section. This section appears when you select the field to total and then select Insert|Grand Total. Crystal Reports uses a rectangular field box, this time to identify the field in the Grand Total section of the Report Editor. o You can add freeform text anywhere on the report by positioning the text cursor in the section in which you want the text to appear, typing in the text, and then using the Tab key to move it into position. You can also type freeform text in a text field; this allows you to avail yourself of additional formatting options (alignment, hide options, etc.). 27.5.1 Auto-Scrolling Capabilities The Report Editor has auto-scrolling capabilities. That is, whenever the cursor hits one of the edges of the Report Editor when you are placing, resizing, or moving a field or drawing a graphic line or box, the Editor automatically scrolls to reveal more workspace (if more is available). 27.5.2 Resizing Sections The Report Editor first appears with default section sizes. You can expand or reduce report sections by dragging the lines that separate the sections. When you position the I-beam cursor over one of those lines, the cursor changes to a double-arrow resizing cursor. Once that cursor appears, you can resize as needed. Alternately, to expand a report section, you can click the section of interest and press Enter as many times as needed. Once you've expanded a section, you can reduce it by deleting unneeded lines with the Backspace key. 27.5.3 A Word about Databases, Records and Fields Before we go any further, a discussion of databases, records, and fields is in order. A record is the basic building block of a database. Each record contains data about a single entity (a customer, an order, etc.), and each database contains at least one record. The data in each record is stored in fields (holding spaces). Each field holds one piece of data known as a value. The database from which you will create a report is a collection of related records. A customer database, for example, is a collection of records that each contain data on a single customer. 27.5.4 Records and Fields in Row/Column Reports Think of the data in a database as being stored in horizontal rows and vertical columns. CustNumber Fname Lname 01034456 Bill Brown 01034457 Jane Doe 01034458 Bob Jackson 01034459 Mary Jones The table above shows field values for four records from such a database (in this case a customer database). o Each row represents one record. All of the data in that row is about a single customer, but the data is broken into three distinct pieces: customer number, first name, and last name. Each of those pieces represents a value found in a field on that record, the CustNumber, Fname, and Lname fields respectively (as indicated by the column headings). o Each column represents one field. All the data in a given column represents the values that appear in that field on each of the records in the database. The structure of a row/column report corresponds to the structure of a database with rows representing individual records and columns representing individual fields. 27.5.5 Records and Fields in Data Block Reports Some reports don't follow the row/column format, however. Instead, some group related data in data blocks. A mailing list, for example, typically uses several rows for each record: a row for the company name, a second row for the street address, a third row for the city, state and ZIP code, etc. In such a report all the data for a given customer in the list appears in a block. Each block represents a single record even though the data in the block spans several rows. 27.5.6 Data Types The data type of a field, (string, number, currency, date, Boolean, or memo) determines the type of information that can be stored in that field and which will print in the report column. Fields of each data type display on your screen like this: XXXXXXX String - for example, a company name, account description or customer name. $5,555,555.55 Currency (Paradox/Btrieve files only) - for example $500.00 or $50,000,000.00-. 5,555,555.55 Number - for example 120 or 5555. YYYY-MM-DD Date - for example Oct 10 90. YES/NO Boolean (YES/NO) data fields - for example, the result of a formula which compares a customer's credit limit to see if it is greater than $5000 and prints YES if the credit limit is more than that amount; NO if it is less than that amount. XXXXXXX Memo - a paragraph describing a piece of property, comments regarding a job applicant, a summary of a movie plot, etc. 27.5.7 Formatting, and Record and Group Selection While formatting, and record and group selection will be covered in depth later, there are a few things about those subjects that are worthwhile to cover here: o Currency, date, and Boolean fields are shown above in the default format. This format is used for both the element markers (in the report editor) and for the report elements themselves (in the report). If you want your data to appear in a different format on your report, you can make the desired changes using the Format|Field command. NOTE: The characters in the element markers change to reflect font changes and many formatting changes (alignment, etc.). o The width and position of a field (when you place it in the Report Editor) determines the initial spacing between fields and the order in which the fields will print across the report page. o When you insert a data field in your report, Crystal Reports assumes that you want to pull data from all the data records in the selected database. To limit the records (or groups of records) used in your report, you need to tell Crystal Reports how to identify the records or groups of records you want to include. Using Edit Record Selection Formula or Edit Group Selection Formula on the Print menu, you can build the selection formula that fits your needs. 27.6 Building Your Prototype To build your report you will follow these steps: o Select the database(s) you wish to use in your prototype report. o Enter and position the data fields, text, and titles you want included in the header, footer, and body of your report. o Print your report to the Print Window and review your work. o Make whatever changes are called for. o Insert your totals, subtotals and other group fields. o Enter and position any formula fields that will calculate or manipulate data or create flags. o Print your report to the Print Window and review your work. o Format the report elements that you want to stand out in some way from the others. 27.6.1 Selecting the Database(s) You use the File|New Report command to begin a report from scratch. That command leads you to a dialog box from which you can select the first database you wish to use. To select additional databases, you use the Database|Add File to Report command. 27.6.2 Entering and Positioning Data Fields Enter and position data fields using the Insert Database Field dialog box that lists available fields in the selected database. Make your selections from the list, and then place the field in your report using the rectangular field placement cursor that appears. 27.6.3 Adding Text You can add text to your report by typing it at the text cursor and then moving it into place. Move the I-beam cursor to the line on which you wish to enter text and click the left mouse button to set the text cursor at the left edge of the Report Editor. Then, simply type in your text, move the I-beam cursor in front of it, and push it into position using the Tab key or Space Bar. You can also add text by inserting text fields and positioning them as you would any other field. 27.6.4 Entering Field Titles By default, Crystal Reports automatically inserts a field title whenever you insert a new field or formula field. The title is a text field that can be edited. The left edge of the title field comes aligned with the left edge of the field it identifies. To toggle this feature off you use the File|Options command. 27.6.5 Printing and Reviewing You can print and review your work in progress at any time using the Print|Print To Window command. When you select this command, Crystal Reports prints your report to the print preview window. 27.6.6 Making Changes Move a database field drag it to a new position with the mouse, or by selecting it and using the Arrow keys. You can move a field within its originating section or to other sections of your report if you wish. To delete a field select it and then press the Delete key or select Edit|Clear. NOTE: To select multiple fields at one time, press the Shift key and, while keeping it depressed, click the various fields you want to select. Handles will appear on each field selected. When finished, you can move or delete the selected fields as a group. 27.6.7 Placing Totals, Subtotals, and Other Group Values To place grand totals select the numeric or dollar field you want to total, and then select Insert|Grand Total from the Menu Bar. Select group values (subtotals, group averages, group counts, etc.) by first selecting the field you want grouped. Then select the kind of group value you want, using the Insert|Subtotal or Insert|Summary commands. Select the kind of group value you want (if you selected Insert|Summary). Then select the field that the program uses to sort and group your data by and the sort direction. 27.6.8 Moving Group Values To move a subtotal or summary drag it to a new position with the mouse, or select it and move it with the Arrow keys. You can move subtotals and summaries only within their originating sections, or from the group footer section to the group header section for the subtotal or summary of interest. 27.6.9 Entering Formulas Enter formulas using the Insert|Formula command. This command calls up the Formula Editor. Using the Formula Editor, build your formula using fields, functions, and operators, and check your work using the built in formula checker. 27.6.10 Formatting You can change the font or point size using the Format|Font command. You can change the alignment and printing characteristics of field data using the Format|Field command, and you can change the conditions that trigger subtotals, add page breaks, suppress blank lines, hide selected sections, etc. using the Format|Section command. Once you have built a prototype report, you have a working model that you can customize to meet your specific needs. 27.7 Manipulating the Data with Formulas and Functions Crystal Reports uses formulas and functions to help you create reports more quickly and easily. It uses them also to allow you to do the kind of "number crunching" and data manipulations that are necessary for advanced reporting. 27.7.1 Formulas A formula is a set of instructions that may be used to calculate information you can't obtain directly from database data fields. For example: o A database record may have a Qty1 field and a Qty2 field but no field that sums both quantities. If you want the sum of these two fields to appear on your report, you need a formula that adds the value in one field to the value in the other. o A database record for a sales rep may contain the field GrossSales and you want to use 120% of that gross as the sales quota for the following year. To accomplish this you need a formula that multiplies GrossSales by 120%. o A database record for a one product company may contain a field Revenue that expresses total dollar sales for the year. You're interested in determining the number of units sold based on an average price of 49.95 per unit. To accomplish this you need a formula that divides Revenue by 49.95. All of these examples require simple formulas: {file.Qty1} + {file.Qty2}, 1.20 * {file.GrossSales}, and {file.Revenue}/49.95 respectively. These formulas all use Crystal Reports operators (+, * [multiply], / [divide]) and they're all easy to create and understand. But not all of your information needs can be reduced to simple formulas; some needs require extensive calculations or manipulations. For example: o You want to determine your average monthly unit sales for the last year, rounded to the nearest unit. o You want to convert ounces of inventory to pounds and ounces, and have it appear in the format x pounds y ounces. The formulas required to accomplish these activities require a fair amount of data manipulation: rounding, averaging, converting numbers to text, calculating remainders, etc. While some of the manipulations (averaging, calculating remainders) can be done using Crystal Reports operators alone, others can't be done without the use of functions. And even the ones that can be done without functions can be done more quickly and efficiently with them. (For additional information on formulas, see Crystal Reports Help.) 27.7.2 Functions A function is a preset procedure or subroutine used to evaluate, make calculations on, or transform data. For example: o the NumericText function evaluates the contents of a text field to see if it is a number, and o the UpperCase function transforms all lowercase characters in a string to uppercase. When you specify a function, Crystal Reports performs the set of operations built into the function without requiring you to specify each operation separately. For example: o the Average function sums a list of values and divides the sum by the number of values in the list. o the DayOfWeek function extracts the day component of a date, determines the day of the week the date falls on, and converts the day of the week to a number (1-7) where Sunday is the first day of the week. By performing multiple operations with a single command, these kinds of functions are a kind of shorthand that make it easier and less time consuming for you to create reports. But not all functions involve lengthy calculations; some simply allow you to do things that you couldn't do easily without them while others take the drudgery out of report creation. For example: o the ToNumber function converts a number that has been stored as text, to a number that can be used in calculations, and o TrimRight removes all the spaces to the right of a string of data stored left-justified in a database. 27.7.3 How Functions are Used Functions are used in formulas. In fact, a single function and its required argument(s) may include the entire formula. For example, Abs ({file.TestResult}) is a perfectly acceptable, stand-alone formula for calculating the absolute value of the field TestResult. 27.7.4 Function Syntax Each function comes with its own set of usage rules (syntax). These rules must be followed for the function to perform correctly. If they are not, Crystal Reports displays a Formula Compiler Error message. As an example, the correct syntax for using the Average([array]) function is: Average ([array]) << where array is an array of constants, field values or calculation results, separated by commas.>> Translated, this means that to use the Average([array]) function correctly, you should enter: Average followed by a list of numeric values, separated by commas, with the list of values enclosed in brackets, and with the array enclosed in parentheses. Thus: Average ([1,2,3,4,5]) is an example of the correct way to use the Average([array]) function. If you try to use the function: o without separating the values by commas, o without enclosing the values in brackets, o without enclosing the array in parentheses, o while including any unnecessary characters, or o with values that are not numeric, Crystal Reports won't accept the formula and will display a Compiler Error message identifying your error. 27.7.5 Entering Formulas and Functions Formulas and functions are entered via Crystal Reports' Formula Editor. The Formula Editor is a dialog box that contains all the tools you need to create and check the correctness of formulas. Using the Editor, you: o assign a name to your formula, o enter the formula, o check it to make sure you have entered it correctly, and then o accept it for use in your report. When you accept it, Crystal Reports places the formula in your report in the position you selected for it. Then, when you print the report, Crystal Reports prints the results of the formula instead of the formula itself. 27.7.6 The Fields Box You can enter fields into your formulas in two ways: via the Fields box, or manually. o To enter a field via the Fields scroll box, you move the I-beam cursor to the place you want to insert the field and click the left mouse button to set the text cursor at that point. Then you locate the field you wish to insert from the Fields scroll box list. - Fields already in use in the report are grouped at the top of the list; other available fields follow. - Formulas you have entered are listed next, their names preceded by the @ sign. - All other fields available in the active databases are listed last, grouped by database. Select a field. Crystal Reports inserts the selected field (complete with the required syntax elements) at the text cursor. NOTE: You select an item from the Formula Editor scroll boxes (Fields, Functions, or Operators) by double clicking it, or by clicking it once to highlight it and then clicking the Select button at the bottom of the Editor to complete the selection process. o To enter a field manually, you locate the text cursor in the appropriate position and type in the field name as you would any text. o The correct syntax for a database field name is: {file.fieldname} If you: - don't include the file name, - leave out the separating period, or - fail to surround the expression in braces, Crystal Reports will generate a Formula Compiler Error message detailing your error. o The correct syntax for a formula field is: {@formulaname} 27.7.7 Operators and Functions Boxes You can also enter operators and functions into your formula in one of two ways: manually or via the Operators and Functions scroll boxes. o To enter an operator or function manually, locate the text cursor in the appropriate position and type in the operator or function as you would any text. o To enter an operator or function via the lists in the Functions and Operators scroll boxes, set the text cursor where you want the entry to appear in the formula. - Then select the item of interest from the scroll box lists. Crystal Reports inserts the selected item in your formula, complete with any parentheses, brackets, or commas required. NOTE: For an array of items, only the first comma is included. As you enter additional items into an array, you will need to type in commas to separate the items. 27.7.8 Order of Precedence When entering formulas that contain different kinds of operators, it is important to consider order of precedence, the order in which Crystal Reports performs the operations in your formula. You learned simple order of precedence in high school math: when performing calculations, do multiplication and division first, then addition and subtraction. Thus: 5 + 10 X 3 = 35 The calculation 10 x 3 is performed first to get 30. 30 is then added to 5 to arrive at the final answer. Now if your intention is to add 5 to 10 and then multiply the sum by 3, you have to modify the order of precedence with parentheses. You can do that thus: (5 + 10) x 3 = 45 It's clear that parentheses have a higher precedence than the add, subtract, multiply, and divide operators. They redirect the order of calculation. You learned all of this in school and Crystal Reports follows the same rules of precedence. But Crystal Reports uses many additional operators, and it's important for you to understand the precedence Crystal Reports assigns to each so you can write your formulas to perform as expected. o In the following list, Crystal Reports performs the top level operations first, then the second level, then the third, and so forth. o When it encounters two or more operations that are on the same level, it performs them left to right. Level 1 Parentheses, Array, IfThenElse Level 2 Call, Subscript Level 3 Identity, Negate, Dollar, Not Level 4 Multiply, Divide, Percent Level 5 Add, Subtract Level 6 To Level 7 Less than, Greater than, Greater than or equal, Less than or equal, In Level 8 Equal, Not equal Level 9 And Level 10 Or 27.7.9 Using Dates in Formulas Crystal Reports includes many useful functions for including dates and date ranges in formulas; you will learn more about those functions in Crystal Reports Help. At this point, however, it's useful to know how to enter any date into a formula. You enter a date simply by entering the Date function (manually or via the Function button) and then providing the date of interest in the parentheses that follow in the form YYYY,MM,DD (1992,01,01 = January 1, 1992). 27.7.10 The Formula Checker The Formula Editor also contains a formula checker which checks the syntax of your formula. If the syntax is incorrect, the formula checker points out the location of the problem and tells you what the problem is. You activate the formula checker by selecting the Check button. Crystal Reports also checks the formula automatically when you choose Accept. When debugging formulas, especially if you have entered them manually, look carefully for: o missing quotation marks around text strings, o missing database name accompanying field names, o missing braces around database name/field name combinations, o missing closing parentheses to match opening parentheses, o case differences (the Formula Checker is case sensitive), o if-then-else formulas that use different data types for the then and else actions, and o using X instead of * for multiplication. The Formula Editor is easy to use and can be called up by selecting Formula from the Insert menu. 27.7.11 Developing Complex Calculations with Formulas Crystal Reports allows you to combine fields, functions, and operators to create complex calculations and manipulations of data. For example, to test the drawing power of two different offers, you can use a single Crystal Reports formula to send one offer to all customers with an even customer number and a second offer to all customers with an odd customer number. You can do some remarkable manipulations using Crystal Reports formulas. 27.8 Grouping, Summarizing, and Sorting Your Data Crystal Reports allows you to group, summarize, and sort your data to achieve the reporting results you want. 27.8.1 Grouping the Data A group is a set of records that are related to each other in some way. In a customer list, for example, a group could consist of all those customers living in the same ZIP code, or in the same state. In a sales report, a group could consist of all the orders placed by the same customer, or all of the orders generated by a specific sales rep. Breaking data into groups (and then doing something to evaluate the group data, if you wish) is a key part of effective reporting. In fact, it's what separates a report from being merely a presentation of raw data and a valuable communication tool. Crystal Reports allows you great flexibility in grouping data. It also gives you the ability to create a number of different kinds of group values. 27.8.2 Group Values A group value is the value generated as the result of an evaluation, a tally, or a calculation performed on data from a single group. A subtotal is one kind of group value; it is the sum of all of the values from a single field, from all the records in a group. In a sales report, for example, if you subtotal sales by sales rep, Crystal Reports gathers all the records that belong to the sales rep and totals the sales amounts from all the records. In a group average, Crystal Reports averages the values in a group of records; in a group count, it counts the values in a group of records, etc. Group values are important tools for creating powerful reports. Crystal Reports gives you several alternatives for working with group data. It enables you to: o calculate the sum of values, o calculate the standard deviation or variance of the values, o average the values, o count the values, o determine the highest value, and o determine the lowest value in the group. 27.8.3 Grouping Data with Crystal Reports While there may be many data fields on a report, there is typically only one field for which you are interested in grouping the data. In a sales report, for example, it would probably be the field listing the amount of sales; in a commission report, it would probably be the field listing the amount of commission, etc. To group data you first select the field you want to group together. Once the field is selected, you select the action you want to take on each group of data from that field: o If you want to simply group the data and take no further action, you can select Insert|Group. o If you want to subtotal it, you can select Insert|Subtotal. o If you want to average, count, determine the maximum or minimum value, etc., you can select Insert|Summary. Subtotals and summaries make up the category of group fields. NOTE: The Insert|Subtotal command is simply a shortcut for setting up a summary that adds the values in each group. Once you have selected the group field and the action, you select another field (a sort and group by field) that triggers a grouping whenever its value changes. In grouping your data by state, for example, you would use the state field to create a new group (and generate a group value if selected) whenever the state changes. Likewise, the ZIP code field would trigger a grouping whenever the ZIP code changes. Once you've made these simple selections, Crystal Reports does the rest. Your data will be grouped, and the group value (if you have selected one) will be calculated and will accompany each group. 27.9 Summarizing the Data Crystal Reports provides three easy-to-use summarizing options: Grand Total A grand total adds all values in a field for the entire report and prints the sum on the last page. Subtotal A subtotal is a partial total, a total of a specific, limited group of data in a field. Summary A summary summarizes field data from a specific, limited group of records. It can total the data like a subtotal, but it can also average the values, count the values, or determine the highest or lowest value in each group or field. All of these options are available on the Insert menu. 27.9.1 The Summarizing Process The process of summarizing the data on your report follows these steps: 1. Selecting the field you want to summarize. 2. Selecting the summarizing option you want from the Insert menu. Finally, if you select Subtotal or Summary as a total type, the process will also include the following step: 3. Selecting the data field that triggers a new subtotal/summary whenever its value changes. 27.9.2 Selecting a Field to Total To select the field you want to summarize, click on it with a mouse. Crystal Reports puts handles on the selected marker to highlight it as selected. 27.9.3 Selecting a Total Type To select a total type, select it from the Insert menu or pop-up menu. 27.9.4 Selecting a Field to Trigger a New Subtotal If you select Subtotal or Summary as a total type, Crystal Reports asks you to indicate the field that is to trigger a new subtotal/summary whenever its value changes. NOTE: For additional information on subtotaling data (with examples), please see section 28.2.32 entitled "Sorting Your Data." 27.10 Sorting There is a logic to the way values are arranged when they appear in a column on your report. Initially, they are arranged in the same order as the data appears in your database. But data can be sorted in a variety of ways: o A mailing list, for example, could be sorted in ascending order, on the ZIP code field; that is, the customers would be sorted so that those with the lowest ZIP codes would appear first and those with the highest ZIP codes would appear last. o It could also be sorted in ascending alphabetical order, on the last name field; that is, customers with last names beginning with A would appear first and those with last names beginning with Z would appear last. o It could also be sorted by street address or customer first name if you had some practical reason for doing so. Crystal Reports gives you the opportunity to change the existing sort order using the Print|Record Sort Order and Print|Group Sort Order commands. 27.10.1 Sorting by Record When you use the Print|Record Sort Order command, Crystal Reports asks you to select two things: o the field you want your sort to be based on (sort field), and o the sort direction. 27.10.2 Sort Field A sort field is a field that determines the order in which data appears on your report. Crystal Reports sorts field data using Windows' sort comparison algorithms, and it uses rules specific to the Country you select in the International section of the Windows Control Panel. You can use any field as a sort field. A field's data type determines the method in which the data from that field is sorted: Text Text fields are sorted in the following manner: One character values are sorted so that blanks have the lowest value, then punctuation, then numbers, then uppercase letters, and finally lowercase letters. Then two character values are sorted, then three, etc. using the same rules. As a result: "BOB" comes before "bob", "123" comes before "124", " " (blank) comes before "a", and "aa" comes before "aaa" Dollars Dollar fields are sorted in numeric order. Number Number values (120, or 5555) are sorted in numeric order. Dates Date fields are sorted in chronological order. Booleans Comparison fields are sorted so that false values come first, then true. When you select a sort field, Crystal Reports sorts the values from that field. 27.10.3 Sort Direction Direction refers to the order in which the values are printed, once sorted. o Ascending order means smallest to largest, 1 to 9, A to Z, False to True. o Descending order means largest to smallest, 9 to 1, Z to A, True to False. 27.10.4 Single Field Sorts Single field sorts are sorts in which all the data in the report is sorted based on the values in a single field. Sorting an inventory report by stock number and sorting a customer list by customer number are examples of single field sorts. 27.10.5 Multiple Field Sorts In multiple field sorts, Crystal Reports first sorts the entries (alphabetic or numeric) in the first field selected, putting them in ascending or descending order as specified. Then it sorts any entries in the second field that can be sorted without disturbing the sort order of entries in the first field. It then sorts any entries in the third field that can be sorted without disturbing the sort order of the entries in the first two fields. It follows the same pattern for sorting additional fields. 27.10.6 Sorting Groups Crystal Reports allows you to change the order in which groups appear on your report. You can: o base the sort on any group (subtotal or summary) in your report, and o sort your report so that group field values appear in ascending or descending order. You change the sort order using the Print|Group Sort Order command. When you sort by group, nothing happens to the sort order of the records within a group; only the relative positions of the groups themselves change. NOTE: For additional information on sorting and examples of single field, multiple field, and group sorts, please see section 28.2.32 entitled "Sorting YourData." 27.11 Editing and Formatting the Data Crystal Reports makes it easy to edit and format your data. The editing/formatting process follows these steps: 1. Selecting the data you want to edit or format. 2. Selecting the editing or formatting action you want to take place. 3. Entering the specifics of the action in the dialog box/editor if/when it appears. 27.11.1 Selecting the Data To select the data element you want to edit or format, you click on it with your mouse. Crystal Reports draws handles on the element marker to highlight it as selected. 27.11.2 Selecting the Action Once the element is selected, you select the editing or formatting action from Crystal Reports' Edit or Format menus. For example: o to change the font used to print the data, select Font from the Format menu, o to hide the field when printing, select Field from the Format menu, or o to modify a formula, select Formula from the Edit menu. 27.11.3 Entering the Specifics In those cases where a dialog box or editor appears after you've selected an action, you enter the specifics of that action in the window that appears. For example: o in the Font dialog box, you enter the font and point size you wish to use, and indicate whether you want the data to appear in boldface or italics, or whether you want it to be underlined or overprinted with the strikeout character, and o in the Formula Editor, you make the changes you want to the formula that appears, check those changes if you wish, and accept the revised formula when you're finished. Crystal Reports takes it from there and performs the action you selected. NOTE: In some cases you have to specify a second action to complete the editing change desired. For example, to move some text in your report, you first cut the text from its current position, and then you paste it in its new position. In such a case you select the data and then the action (Cut) to cut the text to the clipboard. Then you mark the new position using the insertion pointer and select Paste to insert the text in the new position. 27.12 Specifying Records/Groups to be Included When you select a field to appear on your report, Crystal Reports, by default, prints field values from every record in the selected database. But in many cases you may not want to include all the values, but only a specific range of values. For example, you may want to include only a specific group of customers or a specific range of account numbers out of the total number of values in the database. Or you may want to include values from only those records that fall within a particular date range. With Crystal Reports this is easy. The program includes four commands on the Print menu for restricting your report to specific records or groups of records as described in the following sections: 27.12.1 Select Records This option allows you to limit your report to specific records that fit a condition or conditions you specify. It automatically builds a record selection formula using your responses to dialog box questions. This option requires no knowledge of the Crystal Reports formula language. 27.12.2 Edit Record Selection Formula This option also allows you to limit your report to specific records that fit a condition or conditions you specify. It takes you to the Formula Editor where you can manually build a record selection formula to fit your needs. This command is intended for users who are familiar with the Crystal Reports formula language. 27.12.3 Select Groups This option allows you to limit your report to specific groups that fit a condition or conditions you specify. It automatically builds a group selection formula using your responses to dialog box questions. This option requires no knowledge of the Crystal Reports formula language. 27.12.4 Edit Group Selection Formula This option also allows you to limit your report to specific groups of records that fit a condition or conditions you specify. It takes you to the Formula Editor where you can manually build a group selection formula to fit your needs. This command is intended for users who are familiar with the Crystal Reports formula language. You select the command, specify the records or groups of records you want included, and your report prints using only the selected records or groups. 27.13 Printing the Finished Report When you want to print your report or when you want to see what your report will look like when printed, use Crystal Reports' three printing options: o printing to the printer for hard copy output o printing to a print window to review your work o printing to a disk file for use with other applications All of these options are available on the Print menu. When you are creating a report, you will find yourself printing to the print window often, in order to check placement and formatting of the various report elements. The print window even includes a print preview function that lets you see each page of your report as a whole, top to bottom. Then, when you want to print a final or interim copy of the report for hands-on review, you can print to the printer for hard copy output. If you want to use your report data in another application (in a spreadsheet or word processor for example), you can print the report to a disk file in any of a variety of popular file formats. Once in a disk file, you can import the data into your other application following the importing procedures established by the receiving application. 28.0 Practical Crystal Reports This chapter contains a number of topics on the practical aspects of using Crystal Reports to solve typical reporting problems. 28.1 Practical Crystal Reports This chapter contains a number of topics on the practical aspects of using Crystal Reports to solve typical reporting problems. The topics are broken down into the following groups: Creating a report Topics on a variety of report creation skills. Manipulating text and data Topics that show you how to manipulate (copy, delete, move, etc.) text and data on your report. Working with graphics and Topics that show you how to size, scale, graphic enhancements crop, and fine tune the placement of bit-mapped graphics, and how to create, size, and position lines, boxes, and tables on your report. 28.2 Creating a Report This section leads you through the following report creation topics: o Selecting a database o Selecting additional databases o Linking the databases o Understanding the invisible grid o Creating margins o Inserting fields o Selecting fields to move, format, etc. o Spacing fields o Inserting text o Selecting text (to delete, change the font, etc.) o Aligning text with fields o Inserting blank lines o Deleting blank lines o Changing field and text fonts o Highlighting fields with borders and drop shadows o Centering text, field values o Inserting page headers and footers o Inserting page numbers and other special fields o Grouping data o Summarizing grouped data o Creating group headers o Sorting your data o Hiding parts of the report when printing o Selecting records and groups you want included on your report. o Selecting page orientation and paper size 28.2.1 Selecting a Database Begin the report creation process by selecting (activating) a database. Once activated, the database serves as a source from which you can select fields to appear on your report and to be included in report formulas. Select a database using the New Report command on the File menu. 28.2.2 Selecting Additional Databases Crystal Reports allows you to draw data from multiple databases for use in a single report. Select the first database you want to use from the Choose Database File dialog box that appears when you select New Report from the File Menu. Select the second and each additional database using the Add File to Report command on the Database menu. 28.2.3 Linking the Databases You link databases so that records from one database will match up with records from another. For example, if you activate a Customer database and an Order database, you link the databases so that orders in the Order database can be matched up with the customers who placed the orders (from the Customer database). Links are fields that are common to the two databases. The fields don't have to have the same name; but they must have the same structure (size, data type), and contain the same kind of data. o When you activate additional databases using the Database|Add File to Report command, Crystal Reports takes you directly to the Define Link dialog box. You use this dialog box to establish the link between the database you are activating and a database which is already active. o If you later wish to create new links, or update or delete existing links, you use the Database|Links command which takes you to the Links dialog box. Use this dialog box for a variety of linking activities. 28.2.4 Understanding the Invisible Grid The Report Editor looks very freeform. It looks like you can place anything anywhere and hope for good results. But that is not the case. The Editor contains an invisible grid which directly affects the placement of data fields and text fields. Think of the grid as a series of row and column coordinates. Crystal Reports allows you to place fields and text only at these coordinates, not between them. In this way it makes it very easy for you to place and space data on your report, and to align text and fields as needed. If you attempt to place a report element between grid coordinates, Crystal Reports "snaps" the element to the grid (i.e., it moves the element automatically to the nearest coordinate). o When you place a data field in the Report Editor, Crystal Reports "snaps" it to the nearest coordinate. Use the arrow keys or the mouse to move the fields once they have been placed. - When you use the arrow keys to move the field, each time you press the arrow the field moves one grid position. - When you use the mouse to drag the field to a new location, Crystal Reports "snaps" the field to the nearest coordinate as the field moves. o When you type text in the Report Editor, Crystal Reports always begins the text at a grid coordinate. - Use the Tab key to move the text; each time you press the Tab key the text moves six grid positions NOTE: Crystal Reports uses a four pixel horizontal grid and a vertical grid that is variable, based on the line height assigned to the largest font used within a report section. 28.2.5 Creating Margins Set margins in Crystal Reports using the Print|Set Printer Margins command. o Crystal Reports uses a dashed line to display your margins in the Report Editor and Label Editor. o The displayed margins are active: they define the outer printing limits of the report or label. Crystal Reports will not allow you to place or move a field or text so it extends beyond the margins. o The numeric margin settings appear in both the Mailing Labels dialog box and in the Printer Margins dialog box. o When you create a new report, Crystal Reports uses the non-printing areas established for your printer as default margins. For example, if your printer specifications indicate that the left quarter inch of a page is a non-printing area, Crystal Reports sets the default left margin at .25 inches. While you can set margins that fall inside the non-printing areas, parts of your report may be clipped off if you do. o All margins are calculated from the paper edge. Thus, a left margin of .25 inches causes the printing to start exactly one quarter inch in from the edge of the paper. 28.2.6 Inserting Fields Insert fields on your report using the Database Field command on the Insert menu. 28.2.7 Selecting Fields to Move, Format, etc. To do many things with a field (change the font, move it, etc.), first you must to select it. Select means to point to the element with the mouse and then to click the left mouse button to choose the element as the object of the next menu selection. For example, to change font size, you first select the element for which you want to change the font size. Then you select the Font option from the Format menu (or Change Font from the right mouse button menu) to select the new font size. The new font size applies only to the field you selected. When you select a field, black handles appear on the field box. These handles indicate that the field is selected, and therefore active. 28.2.8 Selecting Multiple Fields at One Time To select multiple fields at one time, press the Shift key and, while keeping it depressed, click the various fields you want to select. Handles will appear on each field selected. You can then move or delete the fields as a group. You can also change the font or formatting or add borders for all selected fields. 28.2.9 Spacing Fields Set spacing between data fields by placing the fields where you want them in the Report Editor (using the mouse or Arrow keys), checking your spacing using the Print|Print to Window command, and then fine-tuning the spacing, again in the Report Editor. 28.2.10 Spacing Considerations The following items that can affect column spacing: o Field size - The amount of space allotted for a field may be much greater than the size of the value that appears in the field. - In a number or dollar amount field (which is right justified by default), this can create a large number of leading blank spaces which can impact field spacing. - In all other fields (which are left justified by default), it can create a large number of trailing blank spaces which can impact field spacing. You can reduce the amount of space allotted for a field by selecting the field and then resizing it using the mouse or a Shift-Left Arrow or Shift-Right Arrow key combination. o Mouse - To reduce the size of a field in the Report Editor using the mouse, select the field and then drag either of the handles to make the field box smaller. o Shift-Left Arrow key - To reduce the size of a field in the Report Editor using the Shift-Arrow key combination, select the field, press the Shift key, and, while keeping it depressed, press the Left Arrow key enough times to reduce the field to the desired size. NOTE: If you have set up a data block of fields in the Report Editor (i.e., Customer/Address/City in a customer list report), you can resize all of the fields simultaneously once. First, click each of the fields while holding down the Shift key. Then resize the fields by dragging on one of the sizing handles from any of the selected fields (using the mouse) or by using the Shift-Arrow key combination. o Alignment - Number and dollar amount fields are right justified by default; all other data types are left justified. A right aligned field following a left aligned field may appear to be spaced properly in the Report Editor. You may need to fine tune the spacing, however, once you review the report in the Print Window. 28.2.11 Inserting Text (Titles, Labels, etc.) You can add text to your report by typing it at the insertion point and then moving it into place or, by using the Insert|Text Field command. Use the following procedure to insert text directly on your report: 1. Move the I-beam cursor to the line on which you wish to enter text. 2. Click the left mouse button to set the insertion point at the left margin of the Report Editor. 3. Type in your text. 4. Move the I-beam cursor in front of the text, click to set the insertion point and push the text into position using the Tab key. Use the following procedure to insert text using a text field: 1. Select Insert|Text Field. The Edit Text Field dialog box appears. 2. Enter your text in the Enter Text edit box, and click OK when finished. A rectangular placement cursor appears and changes into a field box when it enters the Report Editor. 3. Position the field box where you want the text field to appear and click the left mouse button to place it. NOTE: By default, Crystal Reports automatically places a title in the Page Header section to identify each field or formula field you insert in your report. These titles are simply text fields. As such, they can be moved, formatted, deleted, resized, or edited to change the text. o For fields, the default title is the name of the field. o For formulas, the default title is the name of the formula. The left edge of each title aligns with the left edge of the field it identifies. Automatic titles can be toggled off and on via the Insert Detail Field Titles option in the Options dialog box. 28.2.12 Selecting Text (To Delete, Change the Font, etc.) To do many things with text (change the font, delete it, etc.), first you must to select it. Select means to highlight the text by dragging the I-beam cursor over it while holding down the left mouse button. Your next action (changing the font, selecting Edit|Cut, etc.) acts upon the text selected. NOTE: When text is in a text field, you select it as you would select any field. 28.2.13 Aligning Text with Fields Often in reporting, you may find yourself wanting to align text with column data (that you entered as fields or formula fields). To do this, place your fields, type your text, and then move the text into position using the Tab key. It is important to understand why you use the Tab key to perform this function and not the Space Bar. Spaces on the screen take up a different amount of space than spaces on the printer. Thus, what looks like it is aligned on screen (using the Space Bar) may not be aligned when you print. If text and fields are aligned to a given tab stop on screen, however, the elements will also be aligned when you print. Since both elements are aligned to the same tab stop, a tab expansion can affect only the absolute position of the elements on a page, not their alignment relative to each other. To align text with fields, you move the text, the field, or both. o Move the text with the Tab key. Each time you press the Tab key the text moves six grid positions. o Move the fields with the Arrow keys. Each time you press one of the Arrow keys, the text moves one grid position. NOTES: a - If you want to center the text over a field, or right or left align it, you can type the text into a text field and use the Format|Field alignment commands to set the alignment of the text within the text field. b - Text can be moved right and left (with the Tab and Backspace keys) as can fields (with the Right Arrow and Left Arrow keys). By moving text and fields in concert, you should be able to get good alignment easily. c - To align field titles with fields, working from left to right is best. Make certain the first title is aligned with its field, then align the second title with its field, etc. Aligning, in this case, consists of aligning the left edge of the title with the left edge of the field. d - For the best (and easiest) alignment of text and field data, enter your text elements as text fields using the Insert|Text Field command (instead of entering the text directly onto the report). 28.2.14 Inserting Blank Lines To insert a blank line, move the I-beam cursor to the section in which you want to enter the blank line, click the left mouse button to set the insertion point, and press Enter one time for each blank line you want to insert. Considerations: o If you place the insertion point before text and then press Enter, the blank lines will appear above the text. o If you place the insertion point after text and then press Enter, the blank lines will appear below the text. o If you place the insertion point before or after a field and then press Enter, the blank lines will always appear below the field. If you want to insert blank lines above the field, insert the number of blanks you need below the field as indicated, and then move the field down to the bottom blank line you have just created. NOTE: You can also add blank lines by dragging the section boundary to increase section size. 28.2.15 Deleting Blank Lines By default the Report Editor allots three lines for the Page Header section and three lines for the Page Footer section of your report. The defaults may allot more lines than you need for those items on your report. Additionally, you may expand a section on your report by a random number of lines prior to inserting text and data, just to make sure you have enough room for your entries. You may find that you have added more lines than necessary. Printing the report without first deleting the unneeded blank lines can leave gaps in your report that make the report less attractive visually and more difficult to read. To delete unneeded blank lines: o If an entire section is blank (i.e., if you aren't putting anything into the Page Footer section of your report), you can eliminate the allotted blank lines by eliminating the entire report section via the Hide Section option of the Format Section command. o If you have text and/or data in a section and just want to remove the extraneous blank lines, click the I-beam cursor on the blank line you want to delete. This sets the insertion point. Once the insertion point is set, press the Backspace key (the key that deletes the previous character); Crystal Reports deletes the line on which the insertion point is set. NOTE: You can also delete blank lines by dragging the section boundary to decrease section size. 28.2.16 Changing Field and Text Fonts You can change fonts quickly for any field value or text string in your report using the Font dialog box. Use the following procedure to change fonts for a field value. 1. Select the field(s) for which you want to change the font. o To select a single field, click the field. o To select multiple fields, hold the Shift key down while you click the fields. Handles appear on the selected field(s). 2. Select Format|Font or click the right mouse button and select Change Font from the pop-up menu. The Font dialog box appears. 3. Make the font, style, size, color, and/or effects changes you want and click OK when finished. Use the following procedure to change fonts for a text string: 1. With the left mouse button depressed, drag the I-beam cursor over the text of interest to select it. 2. Select Format|Font or click the right mouse button and select Change Font from the pop-up menu. The Font dialog box appears. 3. Make the font, style, size, color, and/or effects changes you want and click OK when finished. 28.2.17 Highlighting Fields with Borders and Drop Shadows Crystal Reports makes it easy for you to highlight your data with borders and drop shadows, and color. Use the following procedure to create borders, drop shadows, and add field color: 1. Select the field(s) you want to highlight. o To select a single field, click the field. o To select multiple fields, hold the Shift key down while you click the fields. Handles appear on the selected field(s). 2. Select Format|Border and Colors or click the right mouse button and select Change Border and Colors from the pop-up menu. The Format Border and Colors dialog box appears. 3. Set up the text color, fill (field color), border, and drop shadow you want. 4. Click OK when finished to return to the Report Editor. The selected fields will be highlighted to your specifications. NOTE: If you selected multiple fields, the same highlights will be applied to all fields. If you want to highlight different fields differently, you must select and highlight each unique field individually. 28.2.18 Centering Text, Field Values To center text and field values, you use the Crystal Reports' alignment command. Use the following procedure to center text under a title, over the body of the report, etc. 1. Select Insert|Text Field and create a text field that contains the text you want. 2. Place the text field in the approximate position you want it to appear on the report. 3. Change the font, font size, and font style for the text field if you wish. 4. Resize the text field box so it matches the margins within which you wish to center the text. For example, if you want to center text beneath a report title, expand the field box so it's the same size as the report title (or report title field box). If you want to center a header entry over the body of the report, expand the header entry field box so it's the same width as the data in your report. 5. Select Format|Field, and then select centered from the Alignment box in the Field Format dialog box when it appears. 6. Select OK when finished; Crystal Reports centers your text within the expanded field box. Use the following procedure to center a field value within the space allotted for the field: 1. Select the field whose value you want to center. 2. Change the font, font size, and font style for the field if you wish. 3. Select Format|Field, and then select centered from the Alignment box in the Field Format dialog box when it appears. 4. Select OK when finished; Crystal Reports centers the field value within the space allotted for the field. 28.2.19 Inserting Page Headers and Footers In many cases, you may want to include information at the top and bottom of each page of your report. o At the top of the report (page header) you may want to include such things as the report title, the report date, the range of dates covered by the report, etc. o At the bottom of the report (page footer) you may want to print the page number, the author's name, "Confidential," etc. Crystal Reports makes it easy for you to include such header and footer information. 28.2.20 To Insert Page Headers and Footers You insert page headers and footers by placing the desired information in the appropriate section of the report editor. o header information goes in the Page header section o footer information goes in the Page footer section o Any information you place in these sections prints on each page of the report (unless you take special steps to prevent some printing). o You can use text, fields, or formulas in these sections just as you can in the Details section. 28.2.21 To Format Page Headers and Footers You can format each element in a header or footer in the same way you would format that element if it appeared in the details section: o you can change the font for text, fields, or formulas (see Format|Font), o you can center the values horizontally on the page, center them over your report data, or align them flush left, centered, or flush right within the space allotted for them, o you can change the way dates, numbers, and currency appear when they print, (see Format|Field) and o you can suppress any blank lines that occur in the section (see Format|Section). To format a header or footer element, select the element and then select the formatting option of interest. 28.2.22 Inserting Page Numbers and Other Special Fields Crystal Reports lets you insert special fields in your reports (in addition to the data fields you draw from databases). These special fields allow you to insert dates, page numbers, and group and record numbers in your report. Print Date Field Use Insert|Print Date Field to insert a field that prints whatever is the current date when the report prints. Page Number Field Use Insert|Page Number Field to insert a field that prints the current page number. Record Number Field Use Insert|Record Number Field to have Crystal Reports number each record printed in the Details section of your report. Group Number Field Use Insert|Group Number Field to have Crystal Reports number each group in your report. When you select any of these special fields, a rectangular placement cursor appears. Move the cursor to the point where you want to insert the field and click the left mouse button to place it. 28.2.23 Grouping Data Grouping data means breaking your data into meaningful groups before it appears on your report. Crystal Reports makes it easy: o to group your data, and o to evaluate or perform calculations on the data in each group should you so wish. 28.2.24 Simple Grouping Simple grouping means breaking the data into groups without performing any additional action (totaling, averaging, etc.) on the grouped data. o On a customer list, for example, you may want to group your data by state for use by your customer service or telemarketing personnel. Crystal Reports can quickly organize your data into state groups so that each group contains only customers from a single state. o On a sales report you may want to group data by salesrep (each group containing only sales made by a single salesrep) or by customer (each group containing only sales made to a single customer). Crystal Reports gives you the flexibility to group data in a variety of ways. NOTE: Whenever Crystal Reports groups data, it first sorts the data, and then it breaks the sorted data into groups. For example, if you want to group a customer list by state, Crystal Reports first sorts the data by state. Then it begins a new group whenever the state changes. The following data shows that process. If all you want to do is group your data, you can do this easily with Crystal Reports using the Insert|Group command. Use the following procedure to do simple grouping: 1. Select the field you want to group. For example: - if you want to group a customer list by state, select the field that contains the company name, or - if you want to group an orders report by customer, select the field that contains the order amount. 2. Select Insert|Group Section. The Insert Group Section dialog box appears. 3. In the top scroll box, select the field that you want to trigger a grouping, whenever its value changes. For example: - if you want to group a customer list by state, select the state field, or - if you want to group an orders report by customer, select the field that contains the customer name or customer number. 4. In the second scroll box, select the sort direction (in ascending order = A to Z, 0 to 9, in descending order = Z to A, 9 to 0). 5. If you selected a date or Boolean field in the top scroll box, a third scroll box appears near the bottom of the dialog box. In this scroll box, select the date or Boolean condition that finalizes your subtotal specification. 6. Select OK when finished. Crystal Reports sorts the data and then breaks it into groups according to your specifications. NOTE: You can tell that the data is grouped because two new sections appear in the Report Editor bracketing the Details section. 28.2.25 Nesting Groups You may also want to nest groups of data: group data within a group. For example, on a customer list, you may want to group your data by state, and then, within each state group, break the data down further, by city. Crystal Reports lets you do this easily: you use the Insert|Group Section command two times, first to set up the state group and then to set up the city group. NOTE: You can add additional nesting levels as needed; there is no practical limit to how many nesting levels you can set up. Use the following procedure to group using nesting groups. 1. Select the field you want to group. For example: - if you want to group a customer list by state and then, within each state group, group the list by city, select the field that contains the company name, or - if you want to group an orders report by customer and then, within each customer group, group the list by date, select the field that contains the order amount. 2. Select Insert|Group Section. The Insert Group Section dialog box appears. 3. In the top scroll box, select the field that you want to trigger a grouping, whenever its value changes. For example: - if you want to group a customer list by state and then by city, select the state field, or - if you want to group an orders report by customer and then by date, select the field that contains the customer name or customer number. 4. In the second scroll box, select the sort direction (in ascending order = A to Z, 0 to 9, in descending order = Z to A, 9 to 0) 5. If you selected a date or Boolean field in the top scroll box, a third scroll box appears near the bottom of the dialog box. In this scroll box, select the date or Boolean condition that finalizes your subtotal specification. 6. Select OK when finished. Crystal Reports groups the data according to the first set of specifications. 7. Select the same field you selected in Step 1. 8. Select Insert|Group Section again. The Insert Group Section dialog box appears. 9. This time select the field you want to trigger the second group (the group within the group) whenever its value changes. For example: - if you want to group a customer list by state and then by city, select the city field, or - if you want to group an orders report by customer and then by date, select the date field. 10. Select the sort direction (ascending = A to Z, 0 to 9, descending = Z to A, 9 to 0). 11. Select OK when finished. Crystal Reports groups the data, this time using both sets of specifications. 12. Repeat Steps 6 to 10 for each additional group you want to set up. 28.2.26 Summarizing Grouped Data Sometimes you may want to go beyond mere grouping of data. You may want to first group the data and then evaluate or perform calculations on the data in each group. You may want to sum, average, or count the values, calculate the variance or standard deviation of the values, or determine the highest (maximum) or lowest (minimum) value in each group. o You can sum the data using the Insert|Subtotal or Insert|Summary commands. o You can sum, average, count, calculate the variance or standard deviation, or determine the maximum or minimum values using the Insert|Summary commands. NOTE: Not all summary options are available for every data type. For example, you cannot sum or average string fields. 28.2.27 Grouping and Summarizing Grouped Data 1. Select the field you want to group. For example: - if you want to group a customer list by state and then count the number of values in each group, select the field that contains the company name, or - if you want to group an orders report by customer and then determine the average sized order for each customer, select the field that contains the order amount. 2. Select Insert|Summary. The Insert Summary dialog box appears. 3. In the top scroll box, select the action you want to take on the grouped data. For example: - if you want to count the number of values in each group, select Count, or - if you want to average the values in each group, select Average. 4. In the next scroll box, select the field that you want to trigger a grouping, whenever its value changes. For example: - if you want to group a customer list by state, select the state field, or - if you want to group an orders report by customer, select the field that contains the customer name or customer number. 5. In the next scroll box select the sort direction (ascending = A to Z, 0 to 9, descending = Z to A, 9 to 0). 6. If you selected a date or Boolean field in the top scroll box, a third scroll box appears near the bottom of the dialog box. In this scroll box, select the date or Boolean condition that finalizes your summary specification. 7. Select OK when finished. Crystal Reports sorts the data, and then groups and summarizes it to your specifications. 28.2.29 Grouping and Summarizing Using Nesting Groups 1. Select the field you want to group. For example: - if you want to group and count a customer list by state and then, within each state group, group and count the list by city, select the field that contains the company name, or - if you want to group and sum an orders report by customer and then, within each customer group, group and sum the list by date, select the field that contains the order amount. 2. Select Insert|Summary. The Insert Summary dialog box appears. 3. In the top scroll box, select the action you want to take on the grouped data. For example: - if you want to count the number of values in each group, select Count, or - if you want to average the values in each group, select Average. 4. In the next scroll box, select the field that you want to trigger a grouping, whenever its value changes. For example: - if you want to group a customer list by state, select the state field, or - if you want to group an orders report by customer, select the field that contains the customer name or customer number. 5. In the next scroll box select the sort direction (ascending = A to Z, 0 to 9, descending = Z to A, 9 to 0). 6. If you selected a date or Boolean field in the top scroll box, a third scroll box appears near the bottom of the dialog box. In this scroll box, select the date or Boolean condition that finalizes your summary specification. 7. Select OK when finished. Crystal Reports groups and summarizes the data to your specifications. 8. Select the same field you selected in Step 1. 9. Select Insert|Summary. The Insert Summary dialog box appears. 10. Select the action you want to take on the grouped data. 11. This time select the field you want to trigger the second group (the group within the group) whenever its value changes. For example: - if you want to group and count a customer list by state and then by city, select the city field, or - if you want to group and sum an orders report by customer and then by date, select the date field. 12. Select the sort direction (ascending = A to Z, 0 to 9, descending = Z to A, 9 to 0). 13. Select OK when finished. Crystal Reports groups and summarizes the data to your specifications. 14. Repeat Steps 8 to 14 for each additional group you want to set up. NOTE: Group values (subtotals, summaries) and grand totals are automatically formatted to match as closely as possible the formatting of the field they are summarizing. 28.2.30 Creating Group Headers Just as Crystal Reports allows you to place a header at the top of each page, it also allows you to place incremental headers above each group in your report. This feature allows you to give your reports a polished, professional appearance. Whenever you group your data, or insert a subtotal or a summary, Crystal Reports creates two new sections on your report. o One section, the Group Footer section, appears below the Details section. This section holds the group value field itself. o A matching section, the Group Header section appears above the Details section. Anything you place in this section will appear as a header for your group. NOTE: Both sections are given the same designation so you can tell that they are tied together. The two sections are also tied together visually. o If you put text in the Group Header section, the same text will appear as a header for each group on the report. o If you put the field in the Group Header section that you use for the sort and group by field, Crystal Reports will create a "live" header for each group. For example, if you have a subtotal that groups your data by Customer, putting a duplicate copy of the Customer field in the Group Header section for that subtotal heads each group with the customer name. You can then format this header field to make it stand out if you wish, using a larger point size, bold face or italics, etc. NOTE: You can hide either the Group Header section or the Group Footer section for any group by activating the Hide Section option available via the Format|Section command. 28.2.31 Multiple Groups for the Same Field When you set up a second group for the same field, Crystal Reports creates a second group section on your report beneath the first group section. Likewise, it creates a second Group Header section above the first Group Header section. For each new group field section on an existing field, Crystal Reports creates a pair of sections that effectively "bracket" the existing sections. Each section is clearly marked so you can easily tell which header section goes with each group section. If you place headers in each of the Group Header sections, you produce a report that is extremely easy to read. For example, if you have grouped your data by State and then by City within each state, each new State section will be headed by a State header, and each City section within the State section will be headed by a City header. 28.2.32 Sorting Your Data Crystal Reports allows you to sort your data by record and by group. This section discusses each of the sorting procedures in depth. NOTE: Crystal Reports sorts your data using the sorting rules appropriate to the country that you have selected in the International dialog box in the Windows Control Panel. 28.2.33 Sorting by Record Crystal Reports gives you the ability to sort your data on one or more sort fields. Single and multiple field sorts will be covered in this section. Single field sorts are sorts in which all the data in the report is sorted based on the values in a single field. Sorting an inventory report by stock number and sorting a customer list by customer number are examples of single field sorts. In a multiple field sort, Crystal Reports first sorts the entries (alphabetic or numeric) in the first field selected, putting them in ascending or descending order as specified. Then it sorts any entries in the second field that can be sorted without disturbing the sort order of entries in the first field. It then sorts any entries in the third field that can be sorted without disturbing the sort order of the entries in the first two fields. It follows the same pattern for sorting additional fields. Use the following procedure to sort by record: 1. Select Print|Record Sort Order. The Sort Order dialog box appears. 2. Select the Sort Field(s) and Sort Direction you want and click OK when finished. Crystal Reports sorts the records to your specifications. NOTE: If you group your data using the Insert|Group, Insert|Subtotal, or Insert|Summary command, Crystal Reports sorts your data automatically, as part of the grouping process. For example, if you sort a customer list by state, Crystal Reports first sorts the list alphabetically by state, before breaking it into state groups. In such a case, you do not need to use the Print|Record Sort Order command to generate the sorting. 28.2.34 Sorting Groups Crystal Reports allows you to change the order in which groups appear on your report. You can: o base the sort on any group (subtotal or summary) in your report, and o sort your report so that groups appear in ascending or descending order. When you group data, Crystal Reports first sorts the data by record and then groups it according to your specifications. Here is some data typical of that found in the {file.STATE} field of a customer list: In order to group the data by state, Crystal Reports sorts the original data alphabetically by state, on the first pass, and then it breaks the data into groups (whenever the value in the state field changes) on the second pass. The resulting groups appear in ascending alphabetical order; the group containing all the customers from Arizona comes before the group containing all the customers from Colorado. Now this is fine if you want the groups appearing in that order. But let's assume we want the data grouped so that the group containing the most records (the state with the most customers) appears first, then the state with the second highest number of records, then the third, etc. Crystal Reports lets you do this easily using the Print|Group Sort Order command. Use the following procedure to sort groups. 1. Select the Print|Group Sort Order command. The Sort Order dialog box appears, listing all the groups that you have set up in your report. In our example above, since customer data is grouped by state and the number of records in each state group is counted, a group name similar to this will appear in the Summary Fields box: Group #n:customer.STATECount of customer.CUSTNAME Translated, this means that the {customer.CUSTNAME} field (the field that contains the customer name) is grouped and counted every time the value in the {customer.STATE} field changes. 2. Select this group, click the Add button. Crystal Reports places it in the Sort Fields box and activates the Sort Direction options. 3. Since you want the largest groups (by count) to appear first and the smallest last, select Descending. If you wanted the smallest groups to appear first, you would select Ascending. 4. Click OK when finished. Crystal Reports sorts the groups to your specifications. NOTE: When you sort by group, nothing happens to the sort order of the records within a group; only the relative positions of the groups themselves change. 28.2.35 Hiding Parts of the Report when Printing Crystal Reports has four formatting commands that suppress (hide) various parts of a report. Each of these commands is discussed individually in Crystal Reports Help. The purpose of this section is to show the differences between the commands and how you can use them together to achieve sophisticated report formatting. The four commands are: Suppress if Duplicated Suppress if Duplicated (Field format dialog box) prevents a field value from printing if it is identical to (a duplicate of) the value that comes immediately before it. The value doesn't print but the space in which it would have printed remains. Suppress if Zero Suppress if Zero (Format Number/ Currency dialog boxes) prevents a value from printing if it is a zero value. The value doesn't print but the space in which it would have printed remains. Suppress Blank Lines Suppress Blank Lines (Format Section dialog box) eliminates nonessential blank lines from your report. Hide when Printing Hide when Printing (Field format dialog box) prevents a field from printing. The field doesn't print but the space allotted for the field remains. 28.2.36 Selecting Records and Groups to Include on Your Report You can include all records in your report, or you can restrict your report to specific records or groups of records. For example, you can print a sales report showing year to date sales for all sales reps in the country, or you can print a report that presents nationwide sales but only for the last month, or even a report that shows year to date sales but only for those sales reps in Texas and California. Your reports can be as inclusive or exclusive as you wish. Crystal Reports includes four commands on the Print menu for selecting records and groups. - Select Records - Select Groups - Edit Record Selection Formula - Edit Group Selection Formula o Using the first two commands, Crystal Reports generates a selection formula for you automatically, based on your specifications. o Using the last two commands, you create your own selection formula using the Formula Editor. 28.2.37 Generating a Selection Formula Automatically The Select Records and the Select Groups commands automatically generate record selection formulas based on your responses to dialog box questions. These commands require no knowledge of the Crystal Reports formula language. When you're using these commands, you select a field/group value and respond to questions about how you want to limit that field or group value. For example, if you want to prepare a report limited to Texas customers, you first click the state field in the customer database. Then, you select Print|Select Records (or choose Select Records from the right mouse button menu). When the Select Records dialog box appears you enter your selection criteria in the dialog box. Use the following procedure to have Crystal Reports generate your selection formula: 1. Select the first field/group value you want Crystal Reports to use for determining the records/groups to be included in the report. 2. Select Print|Select Records or Print|Select Groups, whichever is appropriate. NOTE: Alternately, you can select a field or group value and click the right mouse button menu. Select Records appears on the right mouse button menu whenever a field is selected, and Select Groups appears on the right mouse button menu whenever a group value is selected. The Select Records or Select Groups dialog box appears, depending on your selection. 3. Enter your selection criteria in the dialog box and click OK when finished to return to the Report Editor. 4. Repeat Steps 1-3 for each additional field/group value you want the program to use for selecting records/groups. Crystal Reports will generate a selection formula based on your specifications and limit the report to the records or groups you have specified. NOTE: To view or edit the selection formula generated by Crystal Reports, select Print|Edit Record Selection Formula or Print|Edit Group Selection Formula, whichever is appropriate to your selection. 28.2.38 Creating a Selection Formula Manually The Edit Record Selection Formula and Edit Group Selection Formula commands take you to the Formula Editor so you can manually create your own selection formula. Both of these commands require some understanding of the Crystal Reports formula language. Using the Formula Editor, you can build a formula that restricts your report to the records or groups you specify. For example, to limit your report to those records with a customer number greater than 099999, you would build a record selection formula similar to this: {file.CustNumb} >> "099999" To limit your report to those groups with a subtotal on the Amount column (triggered by changes in the CustNumb field) less than $10,000, you would build a group selection formula similar to this: Sum({file.Amount},{file.CustNumb}) << $10000 NOTE: If you select: Grouped by file.CustNumb Sum of file.Amount (the group field of interest in this example) from the Field list, Crystal Reports automatically inserts everything into the formula with the exception of <<$10000. You can also restrict the records used in the report by date. For example, to restrict an invoice report to invoices from a specific month, May 1991 in this case, you would build a record selection formula similar to this: {file.Date}>>=Date(1991,05,01) and {file.Date}<